package com.structure.semaphore;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Semaphore;

/**
 * @Author Tanyu
 * @Date 2020/6/10 17:13
 * @Description
 * @Version 1.0
 */
public class SemaphoreTester {

  public static void main(String[] args) throws InterruptedException {
    //饭店里只用两个洗手池，所以初始化许可证的总数为2。
    Semaphore washbasin = new Semaphore(2, true);

    List<Thread> threads = new ArrayList<>();
    threads.add(new Thread(new Customer(washbasin, "张三")));
    threads.add(new Thread(new Customer(washbasin, "李四")));
    threads.add(new Thread(new Customer(washbasin, "王五")));
    threads.add(new Thread(new Customer(washbasin, "赵六")));

    for (Thread thread : threads
    ) {
      thread.start();
//      thread.join();
      Thread.sleep(50);
    }

//    for (Thread thread : threads) {
//      thread.join();
//    }
  }

}
